package lib

import(
    "net/http"
    "os"
    "io/ioutil"
)

func outputTemplateData(w http.ResponseWriter, r *http.Request, templateName string){
    
    filePath := "template/" + templateName
    fp, err := os.Open(filePath)
    defer fp.Close()
    
    if err != nil{
        w.WriteHeader(404)
        w.Write([]byte("not found!"))
        return
    }
    
    html, err2 := ioutil.ReadAll(fp)
    if err2 != nil{
        w.WriteHeader(500)
        w.Write([]byte("server error!"))
        return
    }
    
    w.Header().Set("Content-Type", "text/html")
    w.WriteHeader(200)
    w.Write(html)
    
}